//
//  WFAboutUsViewController.m
//  WisdomFarm
//
//  Created by sky on 2017/12/13.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFAboutUsViewController.h"
#import "WFAboutQRCodeView.h"

@interface WFAboutUsViewController ()

@property (nonatomic, strong) UIImageView *topBackgroundView;
@property (nonatomic, strong) CAGradientLayer *maskLayer;

@property (nonatomic, strong) UIImageView *logoView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) WFAboutQRCodeView *iosCodeView;
@property (nonatomic, strong) WFAboutQRCodeView *androidCodeView;
@property (nonatomic, strong) UITextView *introduceView;
@property (nonatomic, strong) UIButton *callButton;

@end

@implementation WFAboutUsViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
    UIImage *barImage = [[UIImage alloc] init];
    [self.navigationController.navigationBar setBackgroundImage:barImage forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:barImage];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"关于我们";
    
    self.view.backgroundColor = [UIColor themeColor];
    
    _topBackgroundView = [[UIImageView alloc] init];
    [self.view addSubview:_topBackgroundView];
    _maskLayer = [CAGradientLayer layer];
    _maskLayer.frame = CGRectMake(0, 115, [UIScreen mainScreen].bounds.size.width, 75);
    _maskLayer.colors = @[(id)[[UIColor themeColor] colorWithAlphaComponent:0].CGColor, (id)[[UIColor themeColor] colorWithAlphaComponent:1].CGColor];
    [self.view.layer addSublayer:_maskLayer];
    _logoView = [[UIImageView alloc] init];
    [self.view addSubview:_logoView];
    _nameLabel = [[UILabel alloc] init];
    [self.view addSubview:_nameLabel];
    _iosCodeView = [[WFAboutQRCodeView alloc] init];
    [self.view addSubview:_iosCodeView];
    _androidCodeView = [[WFAboutQRCodeView alloc] init];
    [self.view addSubview:_androidCodeView];
    _introduceView = [[UITextView alloc] init];
    [self.view addSubview:_introduceView];
    _callButton = [[UIButton alloc] init];
    [self.view addSubview:_callButton];
    
    [_topBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.equalTo(self.view.mas_top).offset(190);
    }];
    [_logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.topBackgroundView.mas_bottom).offset(27);
        make.centerX.offset(0);
        make.width.height.mas_equalTo(110);
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.logoView.mas_bottom).offset(10);
        make.centerX.offset(0);
    }];
    [_iosCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(22);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(140);
        make.right.equalTo(self.view.mas_centerX).offset(-40);
    }];
    [_androidCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(22);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(140);
        make.left.equalTo(self.view.mas_centerX).offset(40);
    }];
    [_introduceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.top.equalTo(self.androidCodeView.mas_bottom).offset(25);
        make.bottom.offset(0);
    }];
    [_callButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.height.mas_equalTo(42);
        make.bottom.offset(-15);
    }];
    
    
    _topBackgroundView.contentMode = UIViewContentModeScaleAspectFill;
    _topBackgroundView.image = [UIImage imageNamed:@"login_bg"];
    _topBackgroundView.clipsToBounds = YES;
    
    _logoView.layer.cornerRadius = 55;
    _logoView.image = [UIImage imageNamed:@"about_logo"];
    
    _nameLabel.font = SCFontBold(14);
    _nameLabel.textColor = [UIColor whiteColor];
    _nameLabel.text = @"智慧农业气象";
    
    _iosCodeView.iconView.image = [UIImage imageNamed:@"about_ios"];
    _iosCodeView.codeView.image = [UIImage imageNamed:@"about_code_ios"];
    _iosCodeView.label.text = @"iOS下载";
    [_iosCodeView setNeedsLayout];

    _androidCodeView.iconView.image = [UIImage imageNamed:@"about_android"];
    _androidCodeView.codeView.image = [UIImage imageNamed:@"about_code_android"];
    _androidCodeView.label.text = @"Android下载";
    [_androidCodeView setNeedsLayout];
    
    _introduceView.editable = NO;
    _introduceView.backgroundColor = [UIColor clearColor];
    _introduceView.font = SCFont(14);
    _introduceView.textColor = [UIColor whiteColor];
    _introduceView.text = @"“智慧农业气象”APP是现代农业气象业务服务的延伸和拓展。APP选取不同的空间处理模型将气象观测信息插值到空间区域上形成气象要素分布场，耦合农业气象灾害和农用天气预报指标，利用GIS空间分析与建模技术将农业气象预报预警结果数据进行叠加处理生成图形化的农业气象服务信息及产品，最终实现客户端精细化农业气象灾害监测预警和农用天气预报等服务信息推送。智慧农业气象的主要功能包括定位、一句话农业提示、气象要素显示、适宜农事时间提示、灾害监测预警、适宜农事活动等级预报（农用天气预报）。 ";
    
    _callButton.backgroundColor = [UIColor sc_colorWithHexColor:0xf4c419];
    [_callButton setImage:[UIImage imageNamed:@"about_phone"] forState:UIControlStateNormal];
    [_callButton setTitle:@"400-8000-9284" forState:UIControlStateNormal];
    _callButton.titleLabel.font = SCFont(14);
    [_callButton addTarget:self action:@selector(onCall) forControlEvents:UIControlEventTouchUpInside];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)onCall {
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",[self.callButton currentTitle]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

@end
